void INsertfront(struct ListNode** phead, int x)
{
    assert(phead);
    struct ListNode* newnode = (struct ListNode*)malloc(sizeof(struct ListNode));
    if (newnode == NULL)
    {
        perror("malloc");
    }
    newnode->val = x;
    newnode->next = NULL;

    if (*phead == NULL)
    {
        *phead = newnode;
        return;
    }

    newnode->next = *phead;
    *phead = newnode;

}



struct ListNode* reverseList(struct ListNode* head) {

    if (head == NULL)
    {
        return NULL;
    }
    struct ListNode* newhead = NULL;

    while (head != NULL)
    {
        INsertfront(&newhead, head->val);
        head = head->next;
    }

    return newhead;
